<template>
	<view>
		<view class="nav-box">
			<view class="nav">
				<image class="nav-image" src="../../../static/images/icons/back.svg" @click="back"></image>
				<view class="nav-title">修改昵称</view>
				<button class="nav-button" @click="save" :disabled="flag">保存</button>
			</view>
		</view>
		<input class="uni-input" maxlength="16" v-model="inputNickName" @input="inputEvent"/>
	</view>
</template>

<script>
	import {updateUser} from "../../../static/js/User.js"
	export default {
		data() {
			return {
				"flag": true,
				"inputNickName":""
			}
		},
		onShow() {
			this.userInfo = uni.getStorageSync("userInfo")
			this.inputNickName = this.userInfo.nickname
		},
		methods: {
			back(){
				uni.navigateBack({
					url: '/pages/user/editInfo'
				})
			},
			inputEvent(){
				console.log(this.inputNickName)
				if(this.inputNickName == "" || this.inputNickName == this.userInfo.nickname){
					this.flag = true
				}else{
					this.flag = false
				}
			},
			save(){
				this.userInfo.nickname = this.inputNickName
				updateUser(this.userInfo).then(res=>{
					uni.setStorageSync("userInfo",this.userInfo)
					uni.navigateBack({url: '/pages/user/editInfo'})
				})
			}
		}
	}
</script>

<style>
	@import url("../../../static/css/base.css");
	.uni-input{
		position: relative;
		background-color: #fff;
		margin: 20rpx;
		top: 180rpx;
		border-radius: 20rpx;
		padding: 20rpx 30rpx;
		z-index: 50;
	}
</style>
